package com.xuan.temper.controller;

import com.xuan.email.sendEmail.IMailService;
import com.xuan.temper.entity.ResponeBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @创建人： king xuan
 * @创建时间：2020/10/15
 * @描述：
 */
@RestController
@RequestMapping(value = "/checkTask")
public class CheckTask {

    @Autowired
    private ExponentialTemperatureController exponentialTemperatureController;

    @Autowired
    private IMailService mailService;

    private int sum =0;

    @RequestMapping(value = "/checkTask")
    @Scheduled(cron = "0 0/10 0 * * ?")
    public ResponeBean checkTask() throws ParseException {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
       String [] list = {"000016", "000905", "000300", "399330", "000036", "399006", "000922", "000015", "000807", "000808", "399967"};
        Date date = new Date();
        String todayTime = format.format(date);
        String message="";
        ResponeBean responeBean = exponentialTemperatureController.selectOne(list, todayTime);
        List data = (List) responeBean.getData();
        int size = data.size();
        for (Object datum : data) {
            if (datum==null || datum ==""){
                message="指数温度服务出现问题，有数据请尽快查看";
                if (sum<3){
                    Boolean aBoolean = mailService.sendSimpleMail("1904931470@qq.com", "主题：指数温度服务出现问题", message);
                    if (aBoolean){
                        sum++;
                    }
                }
            }else {
                message="success";
            }
        }
        return new ResponeBean("200", message, responeBean);
    }
}
